/*
 * http://code.google.com/p/anttesttools/
 * jar: commons-io-*.jar
 */
package anttesttools.apachecommons;

import java.io.File;
import java.util.ArrayList;
import org.apache.commons.io.FileUtils;

/**
 *
 * @author anttesttools
 */
public class FileTools
{

    /*
     * 文件目录不存在时，生成目录（包括父目录）
     */
    public static void forceMkdir(File f)
    {
        if (!f.exists())
        {
            try
            {
                FileUtils.forceMkdir(f);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }

        }
    }

    //把list里的内容按行写入文件
    public static void writeList2File()
    {
        File f = new File("file.txt");
        ArrayList lineList = new ArrayList();
        try
        {
            FileUtils.writeLines(f, lineList);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static void read2ListFromFile()
    {
        ArrayList lineList = null;
        File f = new File("file.txt");
        try
        {
            lineList = (ArrayList) FileUtils.readLines(f);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }
}
